package com.borrower.action;

import com.borrower.service.BorrowerServiceImpl;
import com.pojo.BorrowerBean;
import com.utils.EncryptUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class RegisAction extends Action{
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out = response.getWriter();
        String userName = request.getParameter("userName");
        String borPassword = request.getParameter("borPassword");
        String email = request.getParameter("email");
        String idCard = request.getParameter("idCard");
        String phone = request.getParameter("phone");

        String pwd=null;
        try {
            pwd= EncryptUtils.desEncrypt(borPassword);
        } catch (Exception e) {
            e.printStackTrace();
        }

        BorrowerBean bor = new BorrowerBean();
        bor.setBorPwd(pwd);
        bor.setEmail(email);
        bor.setIdCard(idCard);
        bor.setUserName(userName);
        bor.setPhone(phone);

        BorrowerServiceImpl service = new BorrowerServiceImpl();
        if (service.Regis(bor)){
           // System.out.println("注册成功");
            out.println("注册成功");
        }else {
            //System.out.println("注册失败");
            out.println("注册失败");
        }


    }
}
